<template>
  <div id="app">
    <Topbar :key="topbarKey"></Topbar>
    <Header></Header>
    <router-view />
    <Footer></Footer>
    <!-- 登录框 -->
    <Login v-show="$store.state.showModal.isShowLoginModal"></Login>
    <!-- 提示框组件 -->
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>

<script>
import Topbar from "./components/Topbar.vue";
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import Login from "./views/Login.vue";
import Toast from "./components/Toast.vue";
// import axios from "axios";
// import request from "@/request/request";
import { JingPingAPI } from "./request/api";
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState({
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  data() {
    return {
      topbarKey: 0,
    };
  },
  created() {
    // axios
    //   .get("http://192.168.113.249:8081/cms/products/recommend")
    //   .then((res) => {
    //     console.log("res:", res);
    //   });
    // request.get("/products/recommend").then((res) => {
    //   console.log("res:", res);
    // });
    // JingPingAPI().then((res) => {
    //   console.log("res:", res);
    // });
  },
  methods: {
    async fn() {
      let res1 = await JingPingAPI();
      console.log("res1:", res1);
      let res2 = await JingPingAPI();
      console.log("res2:", res2);
      let res3 = await JingPingAPI();
      console.log("res3:", res3);
    },
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        console.log(newVal, oldVal);
        if (oldVal != "/") {
          this.topbarKey++;
        }
      },
    },
  },
};
</script>
<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.5s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
